/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import e.odbo.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_Attribute;

import com.openbravo.bean.Attribute;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

/**
 *
 * @author Administrator
 */
public class AttributeDAO extends ModifiedLogDAO<Attribute>{

    public AttributeDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                    "ATTRIBUTE",
                    new Field[]{
                       new Field(I_Attribute.ID,Datas.STRING, Formats.STRING),
                       new Field(I_Attribute.NAME,Datas.STRING, Formats.STRING),
                       new Field(I_Attribute.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
                     },
                    new int[]{0}
                    );
    }

    @Override
    public void writeInsertValues(DataWrite dp, Attribute obj) throws BasicException {
        dp.setString(1,obj.getId());
        dp.setString(2,obj.getName());
        dp.setTimestamp(3,obj.getLastModified());
    }

    @Override
    public Class getSuportClass() {
       return Attribute.class;
    }

    public Attribute readValues(DataRead dr,Attribute obj) throws BasicException {
        if(obj==null)
    	  obj=new Attribute();
        obj.setKey(dr.getString(1));
        obj.setName(dr.getString(2));
        obj.setLastModified(dr.getTimestamp(3));
        return obj;
    }


}
